<?php
session_start();
require_once 'header.php';
function __autoload($className)
{
    require_once('class/' . $className . '.class.php');
}
$UserId=session::getuserid();
if(!empty($_POST))
{
	$ArrPost=$_POST;
	$Code=$ArrPost['code'];
	$Type=$ArrPost['type'];
	$VarrToCheck=$Code."".$Type;
	$Check=verify::check($VarrToCheck);
	if(($Check==0)&&(is_numeric($Code)==TRUE))
	{
		if($Type=='invitecode')
		{
			$CheckInviteCode=user::checkpermission('checkregis',"username='0'","bath=$Code");
			if($CheckInviteCode==1)
			{
				database::Update('userinfo',array('userid' => $UserId),array('isactive' => '1'));
				database::Update('checkregis',array('bath' => $Code),array('username' => $UserId));
				$_SESSION["erro"]="Your account has been active";
				session::setsessiongroup("user");
				redirect::location("membercp.php");
			}
			else
			{
				$_SESSION["erro"]="This invite code has already be used ! plz use another invite code or send money to active your account";
				redirect::location("activepages.php");
			}
		}
		else if($Type=='lrbatch')
		{
			$CheckLrBatch=user::checkpermission('checkregis', "userinvite='liberty'", "bath=$Code");
			if($CheckLrBatch==0)
			{
				$CheckLr=lrxml::searchistory($Code);
				$CheckLr=30;
				if($CheckLr >=40)
				{
					$AmountAdd=$CheckLr-20;
					database::Update('userinfo',array('userid' => $UserId),array('money' => $AmountAdd,'deposit' => $AmountAdd,'isactive' => '1'));
					database::Insert('checkregis', array('userinvite' => 'liberty','username' => $UserId,'bath' => $Code));
					database::Insert('lrverifier', array('verifier' => $Code));
					$Date=date("Y-m-d");
					database::Insert('payment', array('userid' => $UserId,'date' => $Date,'amount' => $AmountAdd,'reason' => "DEPOSIT to active account",'lr' => $AmountAdd));
					$_SESSION["erro"]="Your account has been actived, and now your balance is: $AmountAdd, we keep 20$ for better service";
					session::setsessiongroup("user");
					redirect::location("membercp.php");
					
				}
				else if(($CheckLr < 40)&&($CheckLr>0)) 
				{
					database::Update('userinfo',array('userid' => $UserId),array('money' => $CheckLr,'deposit' => $AmountAdd,'isactive' => '0'));
					database::Insert('checkregis', array('userinvite' => 'liberty','username' => $UserId,'bath' => $Code));
					database::Insert('lrverifier', array('verifier' => $Code));
					$Date=date("Y-m-d");
					database::Insert('payment', array('userid' => $UserId,'date' => $Date,'amount' => $CheckLr,'reason' => "Can not be actived because less than 40",'lr' => $CheckLr));
					$_SESSION["erro"]="Your account balance has been added $CheckLr but now, your account still Inactive, you have to deposit 40$ for activing your account";
					redirect::location("login.php");
				}
				else 
				{
					$_SESSION["erro"]="We can not find your payment, plz check it by your self and try again";
					redirect::location("activepages.php");
				}
				
			}
			else 
			{
				$_SESSION["erro"]="This Batch code has already be used ! Send another money to active your account";
				redirect::location("activepages.php");
			}
		}
	}
	//print_r($Code);
}
else 
{
	require_once 'html/activepages.php';
}

?>